import Request from '../http/request'
import { _baseURL } from '../http'
const baseURL = _baseURL.ICON_DOWNLOAD
// https://www.axios-http.cn/docs/req_config

const request = new Request(
  baseURL,
  {
    timeout: 10000,
  },
  _request => {
    _request.interceptors.response.use(
      (response: any) => response.data,
      (err: any) => err,
    )
  },
).request

export function getIconNames(iconType: string) {
  return request({
    url: '/collection',
    method: 'get',
    params: {
      prefix: iconType,
    },
  })
}

export function getIconsByName(iconType: string, name: string) {
  const url = `${iconType}.json?icons=${name}`
  return request({
    url,
    method: 'get',
  })
}

export function searchIcon(iconType: string, query: string) {
  return request({
    url: '/search',
    params: {
      query,
      prefix: iconType,
    },
  })
}
